<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ include file="/page/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@ include file="/adapter/adapter-bootstrap.jsp" %>
<script type="text/javascript">
var index=0;
function save(){
	    var v="";
	  var tb=document.getElementById("table");
	  var len=tb.rows.length;
	  if(len<=1){
		  alert("参数列表不可为空");
		  return;
	  }
   	 for(var i=1;i<len;i++)
       	 {    
      
       	 for(var j=0;j<tb.rows[i].cells.length;j++)
           	 { 
       	 	 
           	    var child=tb.rows[i].cells[j].childNodes[0];  
           	     if(child && child.type=="text"){     
               	           v=v+child.value+" ,";//所有文本框的值用逗号分隔加在一起 
               	         
               	    }  
	                  }
                    v=v+";";
             }

    	   $.ajax({
  			type:'post',
  			url:'${pageContext.request.contextPath }/plupmodule/updatemodel?v='+v,
  		    dataType: "json",
  		    data:$("#form").serialize(),
  		    async: false,
  			success:function(data){//返回json结果
      			var addstate=data.model.flag;
      			if(addstate==0){
      				alert("修改失败");
      			}else{
      				alert("修改成功");
      				//window.location.href="${pageContext.request.contextPath }/plupmodule/modulelist";
          			}
  			}
  			
  		});
  	 
         }
function addrow()
{

	  var  html='<tr onclick="selectModule(this,2)";><td><input type="text"  class="form-control" id="param_code" name="param_code"/></td>'+
		'<td><input type="text"  class="form-control" id="param_name" name="param_name"/></td>'+
		'<td><input type="text"  class="form-control" id="param_default_value" name="param_default_value"/></td>'+			
		'<td><input type="text"  class="form-control" id="param_remarks" name="param_remarks"/></td></tr>';
	  $("table").append(html); 
	  
}
function deleteModule(){
	if(index==0){
		alert("请选择一条");
	}else{
		document.getElementById("table").deleteRow(index);
		alert("删除成功");
	}
		
	
}
 
</script>

</head>

<body >

<form class="form-horizontal" role="form" id="form" name="form"  method="post" style="overflow: auto">
          <fieldset>
          <c:if test="${viewState==0}">
                        <input type="button" onclick="addrow()" class="btn btn-default" value="新增"/>
                        <input type="button" onclick="deleteModule()" class="btn btn-default" value="删除"/>
             </c:if>
                        <input type="hidden" name="strid" id="strid"value="${module_id}">
             <table  id="table" class="table table-bordered" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr>
						<th width="200px">参数代码</th>
						<th>参数名称</th>
						<th>参数默认值</th>
						<th>参数作用描述</th>
									
					</tr>
					</thead>
					<tbody>
					<c:if test="${viewState==0}">
				<c:forEach items="${smpList}" var="module" varStatus="s" >
					<tr align="center" class="row_module" id="${module.paramCode}" >
					<td><input type="text" class="form-control" id="param_code" name="param_code" value="${module.paramCode}"/></td>
					<td><input type="text" class="form-control" id="param_name" name="param_name" value="${module.paramName}"/></td>
					<td><input type="text" class="form-control" id="param_default_value" name="param_default_value" value="${module.paramDefaultValue}"/></td>			
					<td><input type="text" class="form-control" id="param_remarks" name="param_remarks" value="${module.paramRemarks}"/></td>
					</tr>
					</c:forEach>
					</c:if>
					<c:if test="${viewState==1}">
					<c:forEach items="${smpList}" var="module" varStatus="s" >
					<tr align="center" class="row_module" id="${module.paramCode}" >
					<td>${module.paramCode}</td>
					<td>${module.paramName}</td>
					<td>${module.paramDefaultValue}</td>			
					<td>${module.paramRemarks}</td>
					</tr>
					</c:forEach>
					</c:if>
					</tbody>		
			</table>                     
                    </fieldset>     
                    <br></br>

					<div class="form-group">
						<div class="col-xs-5"></div>
						<div class="col-xs-5">
						<c:if test="${viewState==0}">
							<button type="button" class="btn btn-default" onclick="save()">&nbsp;&nbsp;确定&nbsp;&nbsp;</button>
							<button type="button" class="btn btn-default"  onclick="history.go(-1)">&nbsp;&nbsp;返回&nbsp;&nbsp;</button>
					     </c:if>
						</div>
					</div>
                    <br></br>
                </form>
                	<script language="javascript">
	    var preRow = null;
		$('tbody tr').bind('click', function() {
	
			var rowIndex = $(this).prevAll().length+1;
			if(rowIndex <1) return;
			
			if(preRow != null){
				preRow.removeClass("active");
			}
			$(this).addClass("active");
			preRow = $(this);
			index=rowIndex;
			// 行单击后事件(传入行号，应用ID,应用名称信息)
		//rowClickA/fter(rowIndex,
			//		$(this).find("td").eq(1).text(),$(this).find("td").eq(2).text());
		});
	</script>
</body>



</html>
